<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
	
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/xadmin/css/font.css">
	<link rel="stylesheet" href="/static/xadmin/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/static/xadmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/xadmin/js/xadmin.js"></script>
	
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">权限管理</a>
        <a>
          <cite>管理员列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe669;</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
          <input type="text" name="T_username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
		  <input type="text" name="T_telephone"  placeholder="请输入手机" autocomplete="off" class="layui-input">
		  <input type="text" name="T_email"  placeholder="请输入邮箱" autocomplete="off" class="layui-input">
          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>搜索</button>
        </form>
      </div>
    <table class="layui-table" lay-data="{url:'/xuser/List',headers: {'X-Requested-With':'XMLHttpRequest'},page:true,toolbar: '#toolbarHead',limit:25,limits:[25, 50,100],id:'UserList'}" lay-filter="UserList">
      <thead>
        <tr> 
          <th lay-data="{type:'checkbox'}"></th>
          <th lay-data="{field:'T_id',sort: true}">ID</th>
		  <th lay-data="{field:'T_username',sort: true}">用户名</th>
          <th lay-data="{field:'T_telephone',sort: true}">手机</th>
          <th lay-data="{field:'T_email',sort: true}">Email</th>
          <th lay-data="{field:'T_lastlogintime',sort: true}">上次登录</th>
          <th lay-data="{field:'T_createtime',sort: true}">创建时间</th>
		  <th lay-data="{field:'T_status',sort: true,templet: '#statusTpl', unresize: true}">状态</th>
          <th lay-data="{field:'T_remark',sort: true}">备注</th>
          <th lay-data="{fixed:'right',align: 'left', toolbar: '#listAction'}">操作</th>
        </tr>
      </thead>
    </table>

  <!-- 添加弹出框	-->
  	<div class="layui-row" id="AddUserInfodiv" style="display:none;">
    	<div class="layui-col-md11">
      		<form class="layui-form layui-form-pane" action="" lay-filter="AddUserInfo">
			 	<div class="layui-form-item">
  					<div class="layui-inline">
    					<label class="layui-form-label">用户名</label>
    					<div class="layui-input-inline" style="width: 213px;">
      						<input type="text" name="T_username" autocomplete="off" lay-verify="nickname" placeholder="" class="layui-input">
    					</div>
						<div class="layui-form-mid" style="color: red;">*</div>
   					</div>

    				<div class="layui-inline">
      					<label class="layui-form-label">手机</label>
      					<div class="layui-input-inline" style="width: 213px;">
        					<input type="text" name="T_telephone" lay-verify="telephone" placeholder="" autocomplete="off"  class="layui-input">
      					</div>
    				</div>

   					<div class="layui-inline">
    					<label class="layui-form-label">邮箱</label>
    					<div class="layui-input-inline" style="width: 213px;">
      						<input type="text" name="T_email" placeholder="" autocomplete="off" lay-verify="email" class="layui-input">
    					</div>
   					</div>

   					<div class="layui-inline">
    					<label class="layui-form-label">密码</label>
    					<div class="layui-input-inline" style="width: 213px;">
      						<input type="password" id="L_pass" name="T_password" placeholder="" lay-verify="pass" autocomplete="off" class="layui-input">
    					</div>
						<div class="layui-form-mid" style="color: red;">*</div>
   					</div>
					
   					<div class="layui-inline">
    					<label class="layui-form-label">确认密码</label>
    					<div class="layui-input-inline" style="width: 213px;">
      						<input type="password" id="L_repass" name="T_repassword" placeholder="" lay-verify="repass" autocomplete="off" class="layui-input">
    					</div>
						<div class="layui-form-mid" style="color: red;">*</div>
   					</div>

      				<div class="layui-inline">
          				<label class="layui-form-label">状态</label>
          				<div class="layui-input-block">
            				<select name="T_status" lay-filter="StatusKey">
              					<option value="2" selected="">启用</option>
			  					<option value="1">禁用</option>
            				</select>
          				</div>
	  				</div>

    				<div class="layui-inline">
      					<label class="layui-form-label">备注</label>
      					<div class="layui-input-inline" style="width: 213px;">
        					<input type="text" name="T_remark" autocomplete="off" class="layui-input">
      					</div>
    				</div>
  				</div>
        		<div class="layui-form-item">
          			<button class="layui-btn" lay-submit="" lay-filter="AddUserSubmit">确认添加</button>
        		</div>
      		</form>
    	</div>
  	</div>
  <!-- 添加弹出框	-->	
    </div>
<script type="text/html" id="statusTpl">
  {{# if (d.T_status == '2') { }}
     <span style="color:#218868">启用</span>
	{{# } else { }}
    <span style="color:#7A8B8B">禁用</span>
{{# } }}
</script>	
<script type="text/html" id="listAction">
  <a class="layui-btn layui-btn-xs" lay-event="Edit"><i class="layui-icon">&#xe642;</i>编辑</a>
  <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="Delete"><i class="layui-icon">&#xe640;</i>删除</a>
</script>	
<script type="text/html" id="toolbarHead">
  <div class="layui-btn-container">
    <button class="layui-btn"  lay-event="AddUser"><i class="layui-icon"></i>添加</button>
	<!-- <button class="layui-btn layui-btn-danger" lay-event="DelUser"><i class="layui-icon"></i>删除</button> -->
  </div>
</script>	
<script>				
      layui.use(['form','table','laydate'], function(){
        var laydate = layui.laydate;
		var table = layui.table;
        var form=layui.form;
        		
          //自定义验证规则
		  form.verify({
			telephone: [/(\d+){11}$/, '必须正确的手机号码']
			,pass: [/(.+){6,12}$/, '密码必须6到12位']
			,repass: function(value){
				if($('#L_pass').val()!=$('#L_repass').val()){
					return '两次密码不一致';
				}
			}
			,email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
		  });
		
		
 //头工具栏事件
  table.on('toolbar(UserList)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'AddUser':							
		layer.open({
        	//layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            type:1,
			skin: 'layui-layer-rim',
            title:"添加节点",
            area: ['500px','550px'],
            content:$("#AddUserInfodiv").html()
        });				
		form.render();	
	
		//添加提交
        form.on('submit(AddUserSubmit)', function(datas){
		   // console.log(datas.field);			
			   layer.confirm('确定添加?', {icon: 3, title:'提示',yes: function(index){
                     $.ajax({
                       url: "/xuser/AddUser",
                       type: "post",
                       data: datas.field,
                       dataType: "json",
                       success: function (resp) {
					            console.log(resp);
                                 if(resp.status){
                                    layer.msg('添加成功', {icon: 1});
									window.location.reload();
                                 }else{
                                    layer.msg('添加失败',{icon:2});
                                 }
                        }
                   });		  	  
               },
                cancel: function(index, layero){ 
                    layer.close(index);
		            console.log("不操作");
                } 
            }); 		   
	      return false; 	
		});			
         break;
      case 'DelUser':
         var data = checkStatus.data;
         layer.msg('选中了：'+ data.length + ' 个');
         break;  
    };
  });		

 
    //监听行工具事件
  table.on('tool(UserList)', function(obj){
    var data = obj.data;
    if(obj.event === 'Edit'){
	     //console.log(data);
	    x_admin_show('编辑用户'+data.Username,'/xuser/UpdateUser?T_id='+data.T_id);
    } else if(obj.event === 'Delete'){
	    //console.log(data);
        layer.confirm('确定删除?', {icon: 3, title:'删除提示',yes: function(index){
			 $.ajax({
			   url: "/xuser/DelUser",
			   type: "post",
			   data: data,
			   dataType: "json",
			   success: function (resp) {
						console.log(resp);
						 if(resp.status){
							 layer.msg('删除成功', {icon: 1});
							 //window.location.reload();
							 obj.del();
						 }else{
							 layer.msg('删除失败',{icon:2});
						 }
				}
		   });		  	  
        },
		cancel: function(index, layero){ 
			layer.close(index);
			console.log("不操作");
		} 
		}); 
    }
  });	
 });  
    </script>
  </body>

</html>